package com.rc.saas.mini.facede;

import com.github.dozermapper.core.Mapper;
import com.rc.saas.mini.common.config.UpYunConfig;
import com.rc.saas.mini.common.utils.CompTimeUtil;
import com.rc.saas.mini.mapper.ugs.TenantUgsLevelDiscountStationMapper;
import com.rc.saas.mini.mapper.ugs.TenantUgsLevelTypeMapper;
import com.rc.saas.mini.mapper.ugs.TenantUgsSuperLevelTypeMapper;
import com.rc.saas.mini.model.elec.ElecStation;
import com.rc.saas.mini.model.elec.ElecStationExample;
import com.rc.saas.mini.model.elec.ElecStationPrice;
import com.rc.saas.mini.model.elec.ElecStationPriceExample;
import com.rc.saas.mini.model.enterprise.EnterpriseMember;
import com.rc.saas.mini.model.hlht.HlhtTenantOpen;
import com.rc.saas.mini.model.hlht.HlhtTenantOpenStation;
import com.rc.saas.mini.model.member.MemberInfo;
import com.rc.saas.mini.model.platform.PlatformArea;
import com.rc.saas.mini.model.platform.PlatformAreaExample;
import com.rc.saas.mini.model.ugs.*;
import com.rc.saas.mini.search.TenantDiscountSearch;
import com.rc.saas.mini.service.discount.TenantDiscountTimeService;
import com.rc.saas.mini.service.elec.ElecStationCollectService;
import com.rc.saas.mini.service.elec.ElecStationPriceService;
import com.rc.saas.mini.service.elec.ElecStationService;
import com.rc.saas.mini.service.enterprise.EnterpriseMemberService;
import com.rc.saas.mini.service.hlht.HlhtTenantOpenService;
import com.rc.saas.mini.service.hlht.HlhtTenantOpenStationService;
import com.rc.saas.mini.service.member.MemberInfoService;
import com.rc.saas.mini.service.platform.PlatformAreaService;
import com.rc.saas.mini.vo.elec.ElecStationExtInfo;
import com.rc.saas.mini.vo.elec.ElecStationUsableVo;
import com.rc.saas.mini.vo.member.MemberLeveDiscountVo;
import com.rc.saas.mini.vo.member.MemberSuperLevelVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Component
public class ElecStationAssemble {
    private static Logger logger = LogManager.getLogger(ElecStationAssemble.class);
    private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

    @Autowired
    private UpYunConfig upYunConfig;

    @Autowired
    private ElecStationPriceService elecStationPriceService;

    @Autowired
    private ElecStationService elecStationService;

    @Autowired
    private PlatformAreaService platformAreaService;

    @Autowired
    private MemberInfoService memberInfoService;

    @Autowired
    private EnterpriseMemberService enterpriseMemberService;

    @Autowired
    private HlhtTenantOpenService hlhtTenantOpenService;

    @Autowired
    private HlhtTenantOpenStationService hlhtTenantOpenStationService;

    @Autowired
    private ElecStationCollectService elecStationCollectService;

    @Autowired
    private TenantDiscountTimeService tenantDiscountTimeService;


    @Autowired
    private TenantUgsLevelDiscountStationMapper tenantUgsLevelDiscountStationMapper;

    @Autowired
    private TenantUgsSuperLevelTypeMapper tenantUgsSuperLevelTypeMapper;

    @Autowired
    private TenantUgsLevelTypeMapper tenantUgsLevelTypeMapper;

    @Autowired
    private Mapper dozerMapper;

    public List<ElecStationExtInfo> assembleStationExtInfo(String tenantCode, MemberInfo member, List<ElecStation> elecStations) {
        if (CollectionUtils.isEmpty(elecStations)) {
            return null;
        }

        //获取新电价 list 增加考虑互联互通
        List<Long> elecStationIds = elecStations.stream().map(ElecStation::getElecStationId).collect(Collectors.toList());

        //根据桩桩攻取电价
        List<ElecStationPrice> basePrices = elecStationPriceService.listStationPriceByDate(elecStationIds);

        //快充，慢充枪的个数list 增加考虑互联互通
        List<ElecStationUsableVo> elecStationInfoVos = elecStationService.listElecStationInfo(elecStationIds);
        //区域
        List<PlatformArea> areas = platformAreaService.selectByExample(new PlatformAreaExample());


        List<ElecStationExtInfo> elecStationFindVos = new ArrayList<>();
        for (ElecStation elecStation : elecStations) {
            //过滤当前桩群id所对应的价格
            List<ElecStationPrice> currentElecStationPrices = basePrices.stream().filter(basePrice -> basePrice.getElecStationId().equals(elecStation.getElecStationId())).collect(Collectors.toList());

            ElecStationUsableVo elecStationInfo =
                    elecStationInfoVos.stream().filter(elecStationInfoVo -> elecStationInfoVo.getElecStationId().equals(elecStation.getElecStationId())).findFirst().orElseGet(() -> null);

            PlatformArea currentArea = areas.stream().filter(area -> area.getAreaId().equals(elecStation.getAreaId())).findFirst().orElseGet(() -> null);

            ElecStationExtInfo elecStationFindVo = assembleElecStationFindVo(elecStation, elecStationInfo, currentElecStationPrices, currentArea);

            if (currentElecStationPrices != null) {
                if (currentElecStationPrices .size()==0) {
                    elecStationFindVo.setCurrentElecStationPrice(null);
                }else{

                    elecStationFindVo.setCurrentElecStationPrice(currentElecStationPrices.get(0));
                }
            }
            //if (!member.getTenantCode().equals(elecStation.getTenantCode())) {
            //    //属于saas互联
            //    elecStationFindVo.setIsSaas(1);
            //}
            elecStationFindVos.add(elecStationFindVo);

        }
        if (member != null && member.getMemberId() != null) {
            member.setTenantCode(tenantCode);
        }

        //根据会员信息查询优惠的桩群
        //elecStationFindVos = assembleMemberDiscount(member, elecStationFindVos);

        return elecStationFindVos;
    }

    /**
     * 单个桩信息封装方法
     */
    private ElecStationExtInfo assembleElecStationFindVo(ElecStation elecStation, ElecStationUsableVo infoVo, List<ElecStationPrice> currentElecStationPrices, PlatformArea area) {
        ElecStationExtInfo elecStationFindVo = new ElecStationExtInfo(elecStation);
        //快充，慢充枪的个数
        if (infoVo != null) {
            elecStationFindVo.setUsableQuickNum(infoVo.getUsableQuickNum());
            elecStationFindVo.setUsableSlowNum(infoVo.getUsableSlowNum());
            elecStationFindVo.setQuickPileNum(infoVo.getQuickPileNum());
            elecStationFindVo.setSlowPileNum(infoVo.getSlowPileNum());
        } else {
            elecStationFindVo.setUsableQuickNum(0);
            elecStationFindVo.setUsableSlowNum(0);
            elecStationFindVo.setQuickPileNum(0);
            elecStationFindVo.setSlowPileNum(0);
        }
        //服务费
        BigDecimal service = BigDecimal.ZERO;
        //电费
        BigDecimal elec = BigDecimal.ZERO;
        BigDecimal totalElec = BigDecimal.ZERO;
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        Date start = null;
        Date end = null;

        try {
            for (ElecStationPrice epgPrice : currentElecStationPrices) {
                Date newDate = sdf.parse(sdf.format(new Date()));
                start = epgPrice.getBeginTime();
                end = epgPrice.getEndTime();

                if (newDate.getTime() >= start.getTime() && newDate.getTime() <= end.getTime()) {
                    totalElec = epgPrice.getElecPrice().add(epgPrice.getServicePrice());
                    service = epgPrice.getServicePrice();
                    elec = epgPrice.getElecPrice();
                    break;
                }
                //如果结束时间为00.00;
                if (end.getTime() == -28800000) {
                    totalElec = epgPrice.getElecPrice().add(epgPrice.getServicePrice());
                    service = epgPrice.getServicePrice();
                    elec = epgPrice.getElecPrice();
                }
            }

        } catch (Exception e) {
            logger.error("日期格式异常", e);
        }

        ArrayList<String> photos = new ArrayList<>();
        if (elecStationFindVo.getPhotos() != null) {
            elecStationFindVo.getPhotos().forEach(s -> {
                if(!s.contains("http")){
                    photos.add(upYunConfig.getDownloadRoot() + s);
                }
            });
        }

        if (area != null) {
            elecStationFindVo.setArea(area.getAreaName());
        }
        //根据pile中的pri_id 判断有没有打印机
        elecStationFindVo.setPhotos(photos);
        elecStationFindVo.setPrintStatus("");
        elecStationFindVo.setElecPrice(elec);
        elecStationFindVo.setServicePrice(service);
        elecStationFindVo.setPvPrice(totalElec.setScale(2, BigDecimal.ROUND_HALF_UP));

        //设置默认价格
        TenantDiscountSearch defaultDiscountSearch = new TenantDiscountSearch();
        defaultDiscountSearch.setPolicyName("原价显示");
        defaultDiscountSearch.setDiscountElecPrice(elecStationFindVo.getElecPrice().setScale(2, BigDecimal.ROUND_HALF_UP));
        defaultDiscountSearch.setDiscountServicePrice(elecStationFindVo.getServicePrice().setScale(2, BigDecimal.ROUND_HALF_UP));
        defaultDiscountSearch.setTotalDiscountPrice(elecStationFindVo.getPvPrice().setScale(2, BigDecimal.ROUND_HALF_UP));
        SimpleDateFormat format2 = new SimpleDateFormat("HH:mm:ss");

        if (start != null) {
            defaultDiscountSearch.setBeginTime(format.format(start));
        } else if (elecStationFindVo.getBizStartTime() != null) {
            defaultDiscountSearch.setBeginTime(elecStationFindVo.getBizStartTime());
        }
        if (end != null) {
            defaultDiscountSearch.setEndTime(format.format(end));
        } else if (elecStationFindVo.getBizEndTime() != null) {
            defaultDiscountSearch.setEndTime(elecStationFindVo.getBizEndTime());
        }

        defaultDiscountSearch.setServicePrice(service);
        defaultDiscountSearch.setElecPrice(elec);
        defaultDiscountSearch.setElecStationId(elecStationFindVo.getElecStationId());
        defaultDiscountSearch.setActivityType(5);

        elecStationFindVo.setBestDiscount(defaultDiscountSearch);
        elecStationFindVo.setShowPlaceType(elecStation.getShowPlaceType());
        elecStationFindVo.setShowPlaceTag(elecStation.getShowPlaceTag());

        return elecStationFindVo;
    }

    /**
     * 获取会员相关优惠的信息
     */
    private List<ElecStationExtInfo> assembleMemberDiscount(MemberInfo member, List<ElecStationExtInfo> elecStationFindVos) {
        //企业会员优惠
        //超级会员 ugs_member_super_level
        //会员等级 ugs_member_level_record

        MemberSuperLevelVo memberSuperLevelVo = memberInfoService.selectMemberSuperLevel(member);

        //enterpriseType(企业类型)0普通企业，1商务企业，null 非企业
        String enterpriseType = null;
        EnterpriseMember enterpriseMember = null;
        if (member != null && member.getBelongEnterpriseId() != null) {
            enterpriseMember = enterpriseMemberService.selectByPrimaryKey(member.getBelongEnterpriseId());
        }
        enterpriseType = enterpriseMember != null ? enterpriseMember.getEnterpriseType() : null;

        //tenant_ugs_level_discount_station 会员等级优惠对应的桩群表
        TenantUgsLevelDiscountStationExample example = new TenantUgsLevelDiscountStationExample();
        example.createCriteria().andTenantCodeEqualTo(member.getTenantCode()).andStatusEqualTo("0").andBeginTimeLessThan(new Date()).andEndTimeGreaterThan(new Date());
        List<TenantUgsLevelDiscountStation> tenantUgsLevelDiscountStations = tenantUgsLevelDiscountStationMapper.selectByExample(example);

        //运营商的vip设置 tenant_ugs_super_level_type
        TenantUgsSuperLevelTypeExample example1 = new TenantUgsSuperLevelTypeExample();
        example1.createCriteria().andTenantCodeEqualTo(member.getTenantCode());
        List<TenantUgsSuperLevelType> tenantUgsSuperLevelTypes = tenantUgsSuperLevelTypeMapper.selectByExample(example1);

       /* //运营商用户等级设置tenant_ugs_member_level  跟member绑定
        TenantUgsMemberLevelExample example2 = new TenantUgsMemberLevelExample();
        example2.createCriteria().andTenantCodeEqualTo(memberSuperLevelVo.getTenantCode()).andMemberIdEqualTo(memberSuperLevelVo.getMemberId());
        List<TenantUgsMemberLevel> tenantUgsMemberLevels = tenantUgsMemberLevelMapper.selectByExample(example2);*/

        //运营商自定义等级tenant_ugs_level_type
        TenantUgsLevelTypeExample example3 = new TenantUgsLevelTypeExample();
        example3.createCriteria().andTenantCodeEqualTo(member.getTenantCode()).andStatusEqualTo("0");
        List<TenantUgsLevelType> tenantUgsLevelTypes = tenantUgsLevelTypeMapper.selectByExample(example3);
        //封装相同的TenantDiscountSearch

        //1个数据时计算时段
        boolean timeCount = false;
        if (elecStationFindVos.size() == 1) {
            timeCount = true;
        }

        for (ElecStationExtInfo elecStationFindVo : elecStationFindVos) {
            if (memberSuperLevelVo != null) {
                //桩群优惠
                getStationDiscount(memberSuperLevelVo, elecStationFindVo);
                //企业会员优惠
                getMemberSuperLevelDiscount(memberSuperLevelVo, elecStationFindVo);
                //超级会员优惠
                getMemberSuperLevelDiscount(elecStationFindVo, memberSuperLevelVo, tenantUgsSuperLevelTypes, tenantUgsLevelDiscountStations, new TenantDiscountSearch());
                //用户等级优惠
                getTenantUgsLevelDiscount(elecStationFindVo, memberSuperLevelVo, tenantUgsLevelTypes, tenantUgsLevelDiscountStations, new TenantDiscountSearch());
            }

            //返回最优
            getPrice2(elecStationFindVo, enterpriseType, timeCount);
        }

        return elecStationFindVos;
    }

    /**
     * 桩群优惠
     */
    private ElecStationExtInfo getStationDiscount(MemberSuperLevelVo memberSuperLevelVo, ElecStationExtInfo elecStationFindVo) {
        //桩群优惠
        if (memberSuperLevelVo.getStationDiscount() != null) {
            //桩群优惠
            TenantDiscountSearch stationDiscount =
                    memberSuperLevelVo.getStationDiscount().stream().filter(tenantDiscount -> tenantDiscount.getElecStationId().equals(elecStationFindVo.getElecStationId())).findFirst().orElseGet(() -> null);
            if (null != stationDiscount) {
                tenantDiscountSearchToChange(stationDiscount);
                elecStationFindVo.setStationDiscount(stationDiscount);
            }
        }

        return elecStationFindVo;
    }

    /**
     * 优惠赋值
     * @param stationDiscount
     * @return
     */
    private TenantDiscountSearch tenantDiscountSearchToChange(TenantDiscountSearch stationDiscount) {
        if (stationDiscount != null) {
            //0服务费打折1特定服务费（活动价）2总价打折
            if (stationDiscount.getDiscountType().equals("0")) {
                if (stationDiscount.getElecPrice() != null && stationDiscount.getServicePrice() != null && stationDiscount.getDiscount() != null) {
                    stationDiscount.setDiscountServicePrice(
                            stationDiscount.getServicePrice().multiply(stationDiscount.getDiscount())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                    stationDiscount.setDiscountElecPrice(stationDiscount.getElecPrice());
                    stationDiscount.setTotalDiscountPrice(
                            stationDiscount.getElecPrice().add(stationDiscount.getServicePrice().multiply(stationDiscount.getDiscount()))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                }
            } else if (stationDiscount.getDiscountType().equals("1")) {
                if (stationDiscount.getDiscountElecPrice() != null && stationDiscount.getServicePrice() != null && stationDiscount.getDiscountServicePrice() != null) {
                    stationDiscount.setTotalDiscountPrice(stationDiscount.getDiscountElecPrice().add(stationDiscount.getDiscountServicePrice()));
                }
            } else if (stationDiscount.getDiscountType().equals("2")) {
                if (stationDiscount.getElecPrice() != null && stationDiscount.getServicePrice() != null && stationDiscount.getDiscount() != null) {
                    stationDiscount.setDiscountServicePrice(
                            stationDiscount.getServicePrice().multiply(stationDiscount.getDiscount())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                    stationDiscount.setDiscountElecPrice(
                            stationDiscount.getElecPrice().multiply(stationDiscount.getDiscount())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                    stationDiscount.setTotalDiscountPrice(
                            (stationDiscount.getServicePrice().add(stationDiscount.getElecPrice())).multiply(stationDiscount.getDiscount())
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));
                }
            }
        }
        return stationDiscount;
    }

    /**
     * 企业会员优惠
     */
    private ElecStationExtInfo getMemberSuperLevelDiscount(MemberSuperLevelVo memberSuperLevelVo, ElecStationExtInfo elecStationFindVo) {
        if (memberSuperLevelVo.getEnterpriseDiscount() != null) {
            //企业会员
            TenantDiscountSearch stationDiscount =
                    memberSuperLevelVo.getEnterpriseDiscount().stream().filter(enterpriseDiscount -> enterpriseDiscount.getElecStationId().equals(elecStationFindVo.getElecStationId())).findFirst().orElseGet(() -> null);
            tenantDiscountSearchToChange(stationDiscount);
            elecStationFindVo.setEnterpriseDiscount(stationDiscount);
        }
        return elecStationFindVo;
    }

    /**
     * 用户等级优惠
     */

    private ElecStationExtInfo getTenantUgsLevelDiscount(ElecStationExtInfo elecStationFindVo, MemberSuperLevelVo memberSuperLevelVo, List<TenantUgsLevelType> tenantUgsLevelTypes,
                                                         List<TenantUgsLevelDiscountStation> tenantUgsLevelDiscountStations,
                                                         TenantDiscountSearch tenantDiscountSearch) {
        if (memberSuperLevelVo.getTenantUgsMemberLevel() != null) {
            //用户等级
            TenantUgsLevelDiscountStation tenantUgsLevelDiscountStation = tenantUgsLevelDiscountStations.stream()
                    .filter(tenantUgsLevelDiscountStation1 -> tenantUgsLevelDiscountStation1.getElecStationId().equals(elecStationFindVo.getElecStationId()))
                    .filter(tenantUgsLevelDiscountStation1 -> memberSuperLevelVo.getTenantUgsMemberLevel().getLevelType().equals(tenantUgsLevelDiscountStation1.getLevelType()))
                    .findFirst().orElseGet(() -> null);
            if (tenantUgsLevelDiscountStation != null) {
                SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
                tenantDiscountSearch.setBeginTime(format.format(tenantUgsLevelDiscountStation.getBeginTime()));
                tenantDiscountSearch.setEndTime(format.format(tenantUgsLevelDiscountStation.getEndTime()));
                tenantDiscountSearch.setDiscount(tenantUgsLevelDiscountStation.getDiscountRatio());
                tenantDiscountSearch.setElecPrice(elecStationFindVo.getBestDiscount().getElecPrice());
                tenantDiscountSearch.setServicePrice(elecStationFindVo.getBestDiscount().getServicePrice());
                tenantDiscountSearch.setPolicyName(Optional.ofNullable(tenantUgsLevelTypes.stream()
                        .filter(tenantUgsLevelType -> tenantUgsLevelType.getLevelType().equals(memberSuperLevelVo.getTenantUgsMemberLevel().getLevelType()))
                        .findFirst().get().getLevelTypeName()).orElseGet(() -> "用户等级优惠"));
                tenantDiscountSearch.setDiscountType(tenantUgsLevelDiscountStation.getDiscountType());
                tenantDiscountSearch = tenantDiscountSearchToChange(tenantDiscountSearch);
                elecStationFindVo.setMemberLevelRecord(tenantDiscountSearch);
            }
        }
        return elecStationFindVo;
    }


    /**
     * 超级会员优惠
     */
    private ElecStationExtInfo getMemberSuperLevelDiscount(ElecStationExtInfo elecStationFindVo, MemberSuperLevelVo memberSuperLevelVo, List<TenantUgsSuperLevelType> tenantUgsSuperLevelTypes,
                                                           List<TenantUgsLevelDiscountStation> tenantUgsLevelDiscountStations, TenantDiscountSearch tenantDiscountSearch) {
        //超级会员
        if (memberSuperLevelVo.getUgsMemberSuperLevel() != null) {
            TenantUgsLevelDiscountStation tenantUgsLevelDiscountStationEnd = tenantUgsLevelDiscountStations.stream()
                    .filter(tenantUgsLevelDiscountStation -> tenantUgsLevelDiscountStation.getElecStationId().equals(elecStationFindVo.getElecStationId()))
                    .filter(tenantUgsLevelDiscountStation -> memberSuperLevelVo.getUgsMemberSuperLevel().getSuperLevelType().equals(tenantUgsLevelDiscountStation.getSuperLevelType()))
                    .findFirst().orElseGet(() -> null);
            if (tenantUgsLevelDiscountStationEnd != null) {
                SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
                tenantDiscountSearch.setBeginTime(format.format(tenantUgsLevelDiscountStationEnd.getBeginTime()));
                tenantDiscountSearch.setEndTime(format.format(tenantUgsLevelDiscountStationEnd.getEndTime()));
                tenantDiscountSearch.setDiscount(tenantUgsLevelDiscountStationEnd.getDiscountRatio());
                tenantDiscountSearch.setElecPrice(elecStationFindVo.getBestDiscount().getElecPrice());
                tenantDiscountSearch.setServicePrice(elecStationFindVo.getBestDiscount().getServicePrice());
                if (tenantUgsSuperLevelTypes.isEmpty()) {
                    tenantDiscountSearch.setPolicyName("超级会员");
                } else {
                    tenantDiscountSearch.setPolicyName(tenantUgsSuperLevelTypes.stream().filter(Objects::nonNull).findFirst().get().getSuperTypeName());
                }
                tenantDiscountSearch.setDiscountType(tenantUgsLevelDiscountStationEnd.getDiscountType());
                tenantDiscountSearch = tenantDiscountSearchToChange(tenantDiscountSearch);
                elecStationFindVo.setMemberSuperLevel(tenantDiscountSearch);
            }
        }
        return elecStationFindVo;
    }

    private ElecStationExtInfo getPrice2(ElecStationExtInfo elecStationFindVo, String enterpriseType, boolean timeCount) {
        //1活动电价 2.超级会员 3.会员等级 4 桩群折扣 5.原价显示 6.企业会员
        //取最优质
        BigDecimal bestPrice = elecStationFindVo.getPvPrice();

        TenantDiscountSearch bestTenantDiscount = elecStationFindVo.getBestDiscount();
        TenantDiscountSearch entBestTenantDiscount = elecStationFindVo.getBestDiscount();
        //当前价格时段对比
        String begin = bestTenantDiscount.getBeginTime();
        String end = bestTenantDiscount.getEndTime();
        //原价
        TenantDiscountSearch priceTenantDiscountSearch = new TenantDiscountSearch();
        priceTenantDiscountSearch.setBeginTime(begin);
        priceTenantDiscountSearch.setEndTime(end);
        //普通企业个人最优
        TenantDiscountSearch personBestDiscount = new TenantDiscountSearch();
        //普通企业企业最优
        TenantDiscountSearch estBestDiscount = new TenantDiscountSearch();
        if ("0".equals(enterpriseType)) {
            //普通企业
            //个人最优   会员等级优惠对比------ 桩优惠价>=超级会员优惠价>=会员等级优惠>=原价
            //会员等级优惠对比
            if (elecStationFindVo.getMemberLevelRecord() != null && bestPrice.compareTo(elecStationFindVo.getMemberLevelRecord().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getMemberLevelRecord().setActivityType(3);
                bestTenantDiscount = elecStationFindVo.getMemberLevelRecord();
                bestTenantDiscount.setBeginTime(begin);
                bestTenantDiscount.setEndTime(end);
                bestPrice = elecStationFindVo.getMemberLevelRecord().getTotalDiscountPrice();
            }
            //超级会员优惠价对比
            if (elecStationFindVo.getMemberSuperLevel() != null && bestPrice.compareTo(elecStationFindVo.getMemberSuperLevel().getTotalDiscountPrice()) > 0) {
                elecStationFindVo.getMemberSuperLevel().setActivityType(2);
                bestTenantDiscount = elecStationFindVo.getMemberSuperLevel();
                bestTenantDiscount.setBeginTime(begin);
                bestTenantDiscount.setEndTime(end);

                bestPrice = elecStationFindVo.getMemberSuperLevel().getTotalDiscountPrice();
            }
            //桩优惠价对比
            if (elecStationFindVo.getStationDiscount() != null && bestPrice.compareTo(elecStationFindVo.getStationDiscount().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getStationDiscount().setActivityType(4);
                bestTenantDiscount = elecStationFindVo.getStationDiscount();
                bestPrice = elecStationFindVo.getStationDiscount().getTotalDiscountPrice();
            }

            //普通企业会员 个人钱包最优价
            elecStationFindVo.setBestDiscount(bestTenantDiscount);


            //普通企业会员 企业钱包
            bestPrice = elecStationFindVo.getPvPrice();
            //桩优惠价对比>=企业会员优惠对比>=原价
            if (elecStationFindVo.getEnterpriseDiscount() != null && bestPrice.compareTo(elecStationFindVo.getEnterpriseDiscount().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getEnterpriseDiscount().setActivityType(6);
                elecStationFindVo.getEnterpriseDiscount().setPolicyName("企业折扣价");
                entBestTenantDiscount = elecStationFindVo.getEnterpriseDiscount();
                bestPrice = elecStationFindVo.getEnterpriseDiscount().getTotalDiscountPrice();
            }
            //桩优惠价对比
            if (elecStationFindVo.getStationDiscount() != null && bestPrice.compareTo(elecStationFindVo.getStationDiscount().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getStationDiscount().setActivityType(4);
                entBestTenantDiscount = elecStationFindVo.getStationDiscount();
            }

            elecStationFindVo.setEnterpriseBestDiscount(entBestTenantDiscount);
            //null app取空值不显示图标
            elecStationFindVo.setEnterpriseDiscount(null);

        } else {
            //普通用户+商业用户
            //企业钱包最优优惠对比------ 桩优惠价》企业会员优惠对>原价
            //会员等级优惠对比
            if (elecStationFindVo.getMemberLevelRecord() != null && bestPrice.compareTo(elecStationFindVo.getMemberLevelRecord().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getMemberLevelRecord().setActivityType(3);
                bestTenantDiscount = elecStationFindVo.getMemberLevelRecord();
                bestTenantDiscount.setBeginTime(begin);
                bestTenantDiscount.setEndTime(end);
                bestPrice = elecStationFindVo.getMemberLevelRecord().getTotalDiscountPrice();
            }
            //企业会员优惠对比
            if (elecStationFindVo.getEnterpriseDiscount() != null && bestPrice.compareTo(elecStationFindVo.getEnterpriseDiscount().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getEnterpriseDiscount().setActivityType(6);
                elecStationFindVo.getEnterpriseDiscount().setPolicyName("企业折扣价");
                bestTenantDiscount = elecStationFindVo.getEnterpriseDiscount();
                bestPrice = elecStationFindVo.getEnterpriseDiscount().getTotalDiscountPrice();
            }

            //超级会员优惠价对比
            if (elecStationFindVo.getMemberSuperLevel() != null && bestPrice.compareTo(elecStationFindVo.getMemberSuperLevel().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getMemberSuperLevel().setActivityType(2);
                bestTenantDiscount = elecStationFindVo.getMemberSuperLevel();
                bestTenantDiscount.setBeginTime(begin);
                bestTenantDiscount.setEndTime(end);

                bestPrice = elecStationFindVo.getMemberSuperLevel().getTotalDiscountPrice();
            }
            //桩优惠价对比
            if (elecStationFindVo.getStationDiscount() != null && bestPrice.compareTo(elecStationFindVo.getStationDiscount().getTotalDiscountPrice()) >= 0) {
                elecStationFindVo.getStationDiscount().setActivityType(4);
                bestTenantDiscount = elecStationFindVo.getStationDiscount();
                bestPrice = elecStationFindVo.getStationDiscount().getTotalDiscountPrice();
            }

            //存储个人最优，商业企业个人最优
            elecStationFindVo.setBestDiscount(bestTenantDiscount);
            elecStationFindVo.setEnterpriseBestDiscount(null);


            if (enterpriseType != null) {
                bestPrice = elecStationFindVo.getPvPrice();
                //企业会员优惠对比
                if (elecStationFindVo.getEnterpriseDiscount() != null && bestPrice.compareTo(elecStationFindVo.getEnterpriseDiscount().getTotalDiscountPrice()) >= 0) {
                    elecStationFindVo.getEnterpriseDiscount().setActivityType(6);
                    elecStationFindVo.getEnterpriseDiscount().setPolicyName("企业折扣价");
                    entBestTenantDiscount = elecStationFindVo.getEnterpriseDiscount();
                    bestPrice = elecStationFindVo.getEnterpriseDiscount().getTotalDiscountPrice();
                }
                //桩优惠价对比
                if (elecStationFindVo.getStationDiscount() != null && bestPrice.compareTo(elecStationFindVo.getStationDiscount().getTotalDiscountPrice()) >= 0) {
                    elecStationFindVo.getStationDiscount().setActivityType(4);
                    entBestTenantDiscount = elecStationFindVo.getStationDiscount();
                }
                elecStationFindVo.setEnterpriseBestDiscount(entBestTenantDiscount);
            }

        }

      /*
        personBestDiscount.setBeginTime(begin);
        personBestDiscount.setEndTime(end);

        elecStationFindVo.getEnterpriseBestDiscount().setBeginTime(begin);
        elecStationFindVo.getEnterpriseBestDiscount().setEndTime(end);*/

        //时间段计算
        if (timeCount) {
            elecStationFindVo.setBestDiscount(timeChange(priceTenantDiscountSearch, elecStationFindVo.getBestDiscount()));
            elecStationFindVo.setEnterpriseBestDiscount(timeChange(priceTenantDiscountSearch, elecStationFindVo.getEnterpriseBestDiscount()));
        }
        return elecStationFindVo;
    }

    //时段选择
    public TenantDiscountSearch timeChange(TenantDiscountSearch price, TenantDiscountSearch tenantDiscountSearch) {
        if (price == null || price.getBeginTime() == null || price.getEndTime() == null || tenantDiscountSearch == null) {
            return tenantDiscountSearch;
        }
        //1.时间区域内  A<=a and b<=B
        if (CompTimeUtil.compTime(tenantDiscountSearch.getBeginTime(), price.getBeginTime()) &&
                CompTimeUtil.compTime(price.getEndTime(), tenantDiscountSearch.getEndTime())) {
            return tenantDiscountSearch;
        }
        //2.左半区  A<=a and and a<=B and B<=b
        else if (CompTimeUtil.compTime(tenantDiscountSearch.getBeginTime(), price.getBeginTime()) &&
                CompTimeUtil.compTime(price.getEndTime(), tenantDiscountSearch.getBeginTime()) &&
                CompTimeUtil.compTime(tenantDiscountSearch.getEndTime(), price.getEndTime())
        ) {
            tenantDiscountSearch.setEndTime(price.getEndTime());

            return tenantDiscountSearch;
        }
        //3.右半区  a<=A and A<=b and b<=B
        else if (CompTimeUtil.compTime(price.getBeginTime(), tenantDiscountSearch.getBeginTime()) &&
                CompTimeUtil.compTime(tenantDiscountSearch.getEndTime(), price.getBeginTime()) &&
                CompTimeUtil.compTime(price.getEndTime(), tenantDiscountSearch.getEndTime())
        ) {
            tenantDiscountSearch.setBeginTime(price.getBeginTime());
            return tenantDiscountSearch;
        }
        //4.中区  a<=A and  B<=b
        else if (CompTimeUtil.compTime(price.getBeginTime(), tenantDiscountSearch.getBeginTime()) &&
                CompTimeUtil.compTime(tenantDiscountSearch.getEndTime(), price.getEndTime())
        ) {
            tenantDiscountSearch.setBeginTime(price.getBeginTime());
            tenantDiscountSearch.setEndTime(price.getEndTime());
            return tenantDiscountSearch;
        }
        return tenantDiscountSearch;
    }

    /**
     * 桩详情
     */
    public ElecStationExtInfo selectStationDetail(MemberInfo member, Long elecStationId, BigDecimal longitude, BigDecimal latitude) {
        ElecStation elecStation = elecStationService.selectStationById(elecStationId, longitude, latitude);

        if (elecStation != null) {
            if (!member.getTenantCode().equals(elecStation.getTenantCode())) {
                //属于saas互联
                //内部互联站点开放
                HlhtTenantOpen hlhtTenantOpen = hlhtTenantOpenService.selectHlhtTenantOpenBySaas(member.getTenantCode(), elecStation.getTenantCode(), "0");
                if (hlhtTenantOpen == null) {
                    return null;
                }
                HlhtTenantOpenStation hlhtTenantOpenStation = hlhtTenantOpenStationService.selectByhlhtTenantOpenStationBySaas(member.getTenantCode(), elecStation.getTenantCode(),
                        elecStation.getElecStationId(), "0");
                if (hlhtTenantOpenStation == null) {
                    return null;
                }
            }

            ArrayList<BigDecimal> elecPrices = new ArrayList<>();
            ArrayList<String> times = new ArrayList<>();
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            String current = sdf.format(new Date());
            //获取新电价
            List<Long> elecStationIds = new ArrayList<>();
            elecStationIds.add(elecStationId);
            List<ElecStationPrice> prices = elecStationPriceService.listStationPriceByDate(elecStationIds);

            PlatformArea area = platformAreaService.selectByPrimaryKey(elecStation.getAreaId());
            //快慢充
            ElecStationUsableVo elecStationInfoVo = elecStationService.countElecStationInfoById(elecStationId);
            //getPrice()
            ElecStationExtInfo elecStationFindVo = assembleElecStationFindVo(elecStation, elecStationInfoVo, prices, area);
            //桩群优惠
            //根据会员信息查询优惠的桩群
            List<ElecStationExtInfo> vos = new ArrayList<>();
            vos.add(elecStationFindVo);
            elecStationFindVo = this.assembleMemberDiscount(member, vos).stream().findFirst().orElseGet(() -> null);
            if (!member.getTenantCode().equals(elecStation.getTenantCode())) {
                //属于saas互联
                elecStationFindVo.setIsSaas(1);
            }
            if (member.getMemberId() != null) {
                //是否收藏
                elecStationFindVo.setIsCollection(elecStationCollectService.selectCollectStatus(member.getMemberId(), elecStationId) ? "1" : "0");
            }

            return elecStationFindVo;
        }
        return null;
    }

    /**
     * 原价+会员价+超级会员价集合
     */
    public MemberLeveDiscountVo selectTimeDiscount(String tenantCode, MemberInfo member, Long elecStationId) {
        ElecStation elecStation = elecStationService.selectByPrimaryKey(elecStationId);
        ElecStationExtInfo elecStationFindVo = new ElecStationExtInfo(elecStation);

        //获取新电价
        ElecStationPriceExample priceExample = new ElecStationPriceExample();
        priceExample.createCriteria().andElecStationIdEqualTo(elecStationId).andUsingStatusEqualTo("0");
        List<ElecStationPrice> prices = elecStationPriceService.selectByExample(priceExample);

        MemberSuperLevelVo memberSuperLevelVo = memberInfoService.selectMemberSuperLevel(member);
        List<TenantDiscountSearch> stationDiscounts = new ArrayList<>();
        List<TenantDiscountSearch> enterpriseDiscounts = new ArrayList<>();
        //String enterpriseType = null;
        //setActivityType 1活动电价 2.超级会员 3.会员等级 4 桩群折扣 5.原价显示 6.企业会员
        if (member != null) {
            TenantDiscountSearch tenantDiscountSearch = new TenantDiscountSearch();
            tenantDiscountSearch.setTenantCode(tenantCode);
            tenantDiscountSearch.setMemberId(member.getMemberId());
            tenantDiscountSearch.setElecStationId(elecStationId);
            stationDiscounts = tenantDiscountTimeService.listDiscountStationAllBySearchNotEnt(tenantDiscountSearch);
            if (member.getEnterpriseMemberId() != null) {
                tenantDiscountSearch.setEnterpriseId(member.getEnterpriseMemberId());
                enterpriseDiscounts = tenantDiscountTimeService.listEnterpriseDiscountAllBySearch(tenantDiscountSearch);
            }
            stationDiscounts = changeTimeByOldAndNew(prices, stationDiscounts);
            enterpriseDiscounts = changeTimeByOldAndNew(prices, enterpriseDiscounts);

            enterpriseDiscounts.forEach(enterpriseDiscount -> {
                tenantDiscountSearchToChange(enterpriseDiscount);
                enterpriseDiscount.setActivityType(6);
            });
            stationDiscounts.forEach(stationDiscount -> {
                tenantDiscountSearchToChange(stationDiscount);
                stationDiscount.setActivityType(4);
            });
            /* EnterpriseMember enterpriseMember = null;
            if (member.getBelongEnterpriseId() != null) {
                enterpriseMember = enterpriseMemberService.selectByPrimaryKey(member.getBelongEnterpriseId());
            }
           //enterpriseType(企业类型)0普通企业，1商务企业，null 非企业
            enterpriseType = enterpriseMember != null ? enterpriseMember.getEnterpriseType() : null;
            //普通企业无个人优化
            enterpriseDiscounts="0".equals(enterpriseType)?null:enterpriseDiscounts;*/

        }

        //运营商自定义等级tenant_ugs_level_type
        TenantUgsLevelTypeExample example3 = new TenantUgsLevelTypeExample();
        example3.createCriteria().andTenantCodeEqualTo(tenantCode).andStatusEqualTo("0");
        List<TenantUgsLevelType> tenantUgsLevelTypes = tenantUgsLevelTypeMapper.selectByExample(example3);

        //运营商的vip设置 tenant_ugs_super_level_type
        TenantUgsSuperLevelTypeExample example1 = new TenantUgsSuperLevelTypeExample();
        example1.createCriteria().andTenantCodeEqualTo(tenantCode);
        List<TenantUgsSuperLevelType> tenantUgsSuperLevelTypes = tenantUgsSuperLevelTypeMapper.selectByExample(example1);

        //tenant_ugs_level_discount_station 会员等级优惠对应的桩群表
        TenantUgsLevelDiscountStationExample example = new TenantUgsLevelDiscountStationExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andStatusEqualTo("0").andElecStationIdEqualTo(elecStationFindVo.getElecStationId())
                .andBeginTimeLessThan(new Date()).andEndTimeGreaterThan(new Date());
        example.setOrderByClause(" begin_time ");
        List<TenantUgsLevelDiscountStation> tenantUgsLevelDiscountStations = tenantUgsLevelDiscountStationMapper.selectByExample(example);
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");

        //用户等级
        //封装相同的TenantDiscountSearch
        MemberLeveDiscountVo memberLeveDiscountVo = new MemberLeveDiscountVo();
        List<TenantDiscountSearch> leve = new ArrayList<>();
        List<TenantDiscountSearch> superLeve = new ArrayList<>();
        //原价
        List<TenantDiscountSearch> costPrice = new ArrayList<>();

        if (prices != null && prices.size() > 0) {
            prices.forEach(price -> {
                        //原价优化 //1活动电价 2.超级会员 3.会员等级 4 桩群折扣 5.原价显示 6.企业会员
                        TenantDiscountSearch costPriceTenantDiscount = new TenantDiscountSearch();
                        costPriceTenantDiscount.setBeginTime(format.format(price.getBeginTime()));
                        costPriceTenantDiscount.setEndTime(format.format(price.getEndTime()));
                        costPriceTenantDiscount.setDiscountServicePrice(price.getServicePrice().setScale(2, BigDecimal.ROUND_HALF_UP));
                        costPriceTenantDiscount.setActivityType(5);
                        costPriceTenantDiscount.setDiscountElecPrice(price.getElecPrice().setScale(2, BigDecimal.ROUND_HALF_UP));
                        costPriceTenantDiscount.setPolicyName("原价");
                        costPrice.add(costPriceTenantDiscount);
                        //会员价，超级会员价
                        if (memberSuperLevelVo != null && tenantUgsLevelDiscountStations != null && tenantUgsLevelDiscountStations.size() > 0) {
                            tenantUgsLevelDiscountStations.forEach(tenantUgsLevelDiscountStation -> {
                                TenantDiscountSearch tenantDiscountSearch = new TenantDiscountSearch();
                                tenantDiscountSearch.setBeginTime(format.format(price.getBeginTime()));
                                tenantDiscountSearch.setEndTime(format.format(price.getEndTime()));
                                tenantDiscountSearch.setDiscountServicePrice(price.getServicePrice());
                                tenantDiscountSearch.setDiscountElecPrice(price.getElecPrice());
                                tenantDiscountSearch.setElecPrice(price.getElecPrice());
                                tenantDiscountSearch.setServicePrice(price.getServicePrice());
                                tenantDiscountSearch.setDiscount(tenantUgsLevelDiscountStation.getDiscountRatio());
                                tenantDiscountSearch.setDiscountType(tenantUgsLevelDiscountStation.getDiscountType());

                                tenantDiscountSearchToChange(tenantDiscountSearch);
                                if (memberSuperLevelVo.getTenantUgsMemberLevel() != null && memberSuperLevelVo.getTenantUgsMemberLevel().getLevelType().equals(tenantUgsLevelDiscountStation.getLevelType())) {
                                    tenantDiscountSearch.setPolicyName(tenantUgsLevelTypes.stream()
                                            .filter(tenantUgsLevelType -> memberSuperLevelVo.getTenantUgsMemberLevel().getLevelType().equals(tenantUgsLevelType.getLevelType()))
                                            .findFirst().map(TenantUgsLevelType::getLevelTypeName).orElseGet(() -> "用户等级优惠"));
                                    tenantDiscountSearch.setActivityType(3);
                                    tenantDiscountSearchToChange(tenantDiscountSearch);

                                    leve.add(tenantDiscountSearch);
                                } else if (memberSuperLevelVo.getUgsMemberSuperLevel() != null && tenantUgsLevelDiscountStation.getSuperLevelType() != null &&
                                        memberSuperLevelVo.getUgsMemberSuperLevel().getSuperLevelType().equals(tenantUgsLevelDiscountStation.getSuperLevelType())) {
                                    if (tenantUgsSuperLevelTypes.isEmpty()) {
                                        tenantDiscountSearch.setPolicyName("超级会员");
                                    } else {
                                        tenantDiscountSearch.setPolicyName(tenantUgsSuperLevelTypes.stream().filter(Objects::nonNull).findFirst().get().getSuperTypeName());
                                    }

                                    tenantDiscountSearchToChange(tenantDiscountSearch);
                                    tenantDiscountSearch.setActivityType(2);
                                    superLeve.add(tenantDiscountSearch);
                                }
                            });
                        }
                    }
            );
        }

        memberLeveDiscountVo.setLeveTimePrice(leve.size() > 0 ? leve : null);
        memberLeveDiscountVo.setSuperLeveTimePrice(superLeve.size() > 0 ? superLeve : null);
        memberLeveDiscountVo.setCostPrice(costPrice.size() > 0 ? costPrice : null);
        memberLeveDiscountVo.setEnterpriseTimePrice(enterpriseDiscounts.size() > 0 ? enterpriseDiscounts : null);
        memberLeveDiscountVo.setStationTimePrice(stationDiscounts.size() > 0 ? stationDiscounts : null);
        return memberLeveDiscountVo;
    }

    /**
     * 2个时段对比
     */
    public List<TenantDiscountSearch> changeTimeByOldAndNew(List<ElecStationPrice> prices, List<TenantDiscountSearch> tenantDiscountSearches) {
        List<TenantDiscountSearch> returns = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");


        if (tenantDiscountSearches != null) {
            if (tenantDiscountSearches.size() > 0 && "1".equals(tenantDiscountSearches.get(0).getDiscountType())) {
                //特定时间段服务费
                return tenantDiscountSearches;
            }
            for (ElecStationPrice price : prices) {
                for (TenantDiscountSearch tenantDiscountSearch : tenantDiscountSearches) {

                    TenantDiscountSearch newData = dozerMapper.map(tenantDiscountSearch, TenantDiscountSearch.class);

                    if (returns == null || returns.size() < prices.size()) {
                        //1.时间区域内  A<=a and b<=B
                        if (CompTimeUtil.compTime(newData.getBeginTime(), format.format(price.getBeginTime())) &&
                                CompTimeUtil.compTime(format.format(price.getEndTime()), newData.getEndTime())) {
                            newData.setBeginTime(format.format(price.getBeginTime()));
                            newData.setEndTime(format.format(price.getEndTime()));
                            newData.setServicePrice(price.getServicePrice());
                            newData.setElecPrice(price.getElecPrice());
                            returns.add(newData);
                        }
                        //2.左半区  A<=a and and a<=B and B<=b
                        else if (CompTimeUtil.compTime(newData.getBeginTime(), format.format(price.getBeginTime())) &&
                                CompTimeUtil.compTime(format.format(price.getEndTime()), newData.getBeginTime()) &&
                                CompTimeUtil.compTime(newData.getEndTime(), format.format(price.getEndTime()))
                        ) {
                            newData.setBeginTime(format.format(price.getBeginTime()));
                            newData.setServicePrice(price.getServicePrice());
                            newData.setElecPrice(price.getElecPrice());
                            returns.add(newData);
                        }
                        //3.右半区  a<=A and A<=b and b<=B
                        else if (CompTimeUtil.compTime(format.format(price.getBeginTime()), newData.getBeginTime()) &&
                                CompTimeUtil.compTime(newData.getEndTime(), format.format(price.getBeginTime())) &&
                                CompTimeUtil.compTime(format.format(price.getEndTime()), newData.getEndTime())
                        ) {
                            newData.setEndTime(format.format(price.getEndTime()));
                            newData.setServicePrice(price.getServicePrice());
                            newData.setElecPrice(price.getElecPrice());
                            returns.add(newData);
                        }
                        //4.中半区  a<=A and  B<=b
                        else if (CompTimeUtil.compTime(format.format(price.getBeginTime()), newData.getBeginTime()) &&
                                CompTimeUtil.compTime(newData.getEndTime(), format.format(price.getEndTime()))
                        ) {

                            newData.setServicePrice(price.getServicePrice());
                            newData.setElecPrice(price.getElecPrice());
                            returns.add(newData);
                        }
                    } else {
                        break;
                    }
                }
            }
        }

        return returns;
    }

    /**
     * 桩详情
     */
    public ElecStationExtInfo selectElecStationDetail(MemberInfo member, Long elecStationId) {
        ElecStationExample example = new ElecStationExample();
        example.createCriteria().andOperateStatusEqualTo("1").andElecStationIdEqualTo(elecStationId);
        ElecStation elecStation = elecStationService.selectByExample(example).stream().findFirst().orElseGet(() -> null);

        if (!member.getTenantCode().equals(elecStation.getTenantCode())) {
            //属于saas互联
            HlhtTenantOpen hlhtTenantOpen = hlhtTenantOpenService.selectHlhtTenantOpenBySaas(member.getTenantCode(), elecStation.getTenantCode(), "0");
            if (hlhtTenantOpen == null) {
                return null;
            }
        }
        if (elecStation != null) {
            ArrayList<BigDecimal> elecPrices = new ArrayList<>();
            ArrayList<String> times = new ArrayList<>();
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            String current = sdf.format(new Date());
            //获取新电价
            List<Long> elecStationIds = new ArrayList<>();
            elecStationIds.add(elecStationId);
            List<ElecStationPrice> prices = elecStationPriceService.listStationPriceByDate(elecStationIds);

            PlatformArea area = platformAreaService.selectByPrimaryKey(elecStation.getAreaId());
            //快慢充
            ElecStationUsableVo elecStationInfoVo = elecStationService.countElecStationInfoById(elecStationId);
            //getPrice()
            ElecStationExtInfo elecStationFindVo = assembleElecStationFindVo(elecStation, elecStationInfoVo, prices, area);
            //桩群优惠
            //根据会员信息查询优惠的桩群
            List<ElecStationExtInfo> vos = new ArrayList<>();
            vos.add(elecStationFindVo);
            elecStationFindVo = this.assembleMemberDiscount(member, vos).stream().findFirst().orElseGet(() -> null);
            if (!member.getTenantCode().equals(elecStation.getTenantCode())) {
                //属于saas互联
                elecStationFindVo.setIsSaas(1);
            }
            if (member.getMemberId() != null) {
                //是否收藏
                elecStationFindVo.setIsCollection(elecStationCollectService.selectCollectStatus(member.getMemberId(), elecStationId) ? "1" : "0");
            }

            return elecStationFindVo;
        }
        return null;
    }




}
